package dfbz.com.controller.user;

import dfbz.com.controller.BaseServlet;
import dfbz.com.service.UserService;
import dfbz.com.service.impl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/myuser/*")
public class UserServlet extends BaseServlet {
    private UserService userService = new UserServiceImpl();


    public void list(HttpServletRequest request, HttpServletResponse response) {
        String page1 = request.getParameter("page");
        String search = request.getParameter("searchname");
//        String search1 = userService.search(search);
//        System.out.printf(search1);
        int page = 1;
//         int pages = Integer.parseInt(page1);
        if (page1 != null) {
            page = Integer.parseInt(page1);
        }
        int count=userService.searchTotal(search).size()/5+1;
        request.setAttribute("usertotal", count  );
        request.setAttribute("userinfoList",userService.search(search,page));
        try {
            request.getRequestDispatcher("/html/user.jsp").forward(request, response);
        } catch (ServletException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
